<template>
  <div>
    <el-table v-loading="loading" :data="dataSource" border :height="autoHeight">
      <el-table-column prop="dataLabel" label="名称" align="center">
        <template slot="header" slot-scope="scope">
          <div>{{ scope.column.label }}</div>
          <el-input v-model="filterModel[scope.column.property]" :placeholder="scope.column.label + '过滤'" clearable @change="filterChange(scope.column.property)"></el-input>
        </template>
        <template slot-scope="scope">
          <el-input v-if="scope.row.editAbled" v-model="scope.row[scope.column.property]" :placeholder="scope.column.label" clearable></el-input>
          <span v-else>{{scope.row[scope.column.property]}}</span>
        </template>
      </el-table-column>
      <el-table-column prop="dataValue" label="值" align="center">
        <template slot="header" slot-scope="scope">
          <div>{{ scope.column.label }}</div>
          <el-input v-model="filterModel[scope.column.property]" :placeholder="scope.column.label + '过滤'" clearable @change="filterChange(scope.column.property)"></el-input>
        </template>
        <template slot-scope="scope">
          <el-input v-if="scope.row.editAbled" v-model="scope.row[scope.column.property]" :placeholder="scope.column.label" clearable></el-input>
          <span v-else>{{scope.row[scope.column.property]}}</span>
        </template>
      </el-table-column>
      <el-table-column prop="dataCode" label="编码" align="center">
        <template slot="header" slot-scope="scope">
          <div>{{ scope.column.label }}</div>
          <el-input v-model="filterModel[scope.column.property]" :placeholder="scope.column.label + '过滤'" clearable @change="filterChange(scope.column.property)"></el-input>
        </template>
        <template slot-scope="scope">
          <el-input v-if="scope.row.editAbled" v-model="scope.row[scope.column.property]" :placeholder="scope.column.label" clearable></el-input>
          <span v-else>{{scope.row[scope.column.property]}}</span>
        </template>
      </el-table-column>
      <el-table-column prop="dataMapper" label="映射" align="center">
        <template slot="header" slot-scope="scope">
          <div>{{ scope.column.label }}</div>
          <el-input v-model="filterModel[scope.column.property]" :placeholder="scope.column.label + '过滤'" clearable @change="filterChange(scope.column.property)"></el-input>
        </template>
        <template slot-scope="scope">
          <el-input v-if="scope.row.editAbled" v-model="scope.row[scope.column.property]" :placeholder="scope.column.label" clearable></el-input>
          <span v-else>{{scope.row[scope.column.property]}}</span>
        </template>
      </el-table-column>
      <el-table-column prop="dataOrder" label="排序" align="center">
        <template slot-scope="scope">
          <el-input-number v-if="scope.row.editAbled" v-model="scope.row[scope.column.property]" :placeholder="scope.column.label" clearable style="width: 100%"></el-input-number>
          <span v-else>{{scope.row[scope.column.property]}}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="操作" width="120px">
        <template slot="header" slot-scope="scope">
          <el-button v-if="scope" type="primary" @click="() => { dataSource.splice(0,0,{editAbled:true, dictId: dictInfo.dictId })}" icon="el-icon-circle-plus-outline">新增</el-button>
        </template>
        <template slot-scope="scope">
          <el-button v-if="scope.row.editAbled" type="warning" icon="el-icon-circle-check" circle @click="saveData(scope.row)" title="保存"></el-button>
          <el-button v-else type="success" icon="el-icon-edit" circle @click="() => { $set(scope.row, 'editAbled', true)}" title="编辑"></el-button>
          <el-button type="danger" icon="el-icon-delete" circle @click="removeData(scope.row, scope.$index)" title="删除"></el-button>
        </template>
      </el-table-column>
    </el-table>
    <div class="lab-table-page">
      <div style="display: inline-flex">
        <el-pagination
            :disabled="loading"
            :current-page="pageInfo.page"
            :page-sizes="[5, 10, 15, 20, 50, 100]"
            :page-size="pageInfo.pageSize"
            layout="total, sizes, prev, pager, next, jumper"
            :total="pageInfo.total"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
        />
        <el-button-group style="padding: 2px 5px">
          <el-button icon="el-icon-refresh" title="刷新" :disabled="loading" @click="loadSource([])" />
        </el-button-group>
      </div>
    </div>
  </div>
</template>

<script>
import IdeaTable from "@/mixins/IdeaTable";

export default {
  name: "AppDictData",
  mixins: [IdeaTable],
  props: {
    dictInfo: {
      type: Object,
      default: function () {
        return {}
      }
    }
  },
  computed:{
    autoHeight() {
      return `calc(100vh - 305px)`
    }
  },
  created() {
    this.queryUrl = 'dictData/queryPage'
    this.removeUrl = 'dictData/delete/'
    this.saveUrl = 'dictData/save'
    this.rowKey = 'dataId'
    this.addFilter({field: 'dictId',op: '=', value: this.dictInfo.dictId})
    this.pageInfo.sorts = [{field:'dataOrder',asc:false}]
    this.loadSource()
  }
}
</script>

<style scoped>

</style>
